<?php
class Impact_View_Helper_SelectControl extends Impact_View_Helper_FormControl
{
    public function selectControl($id, $value, $options = array(), $attributes = array()) 
    {
        if (empty($attributes['name'])) {
            $attributes['name'] = $id;
        }

        $attributes['id'] = $id;

        $html = '<select ' . $this->_buildAttributeString($attributes) . '>';

        if (!is_array($value)) {
            $valueArray = array((string) $value);
        } else {
            $valueArray = $value;
        }

        foreach ($options as $optionValue => $optionLabel) {
            $optionAttributes = array('value' => $optionValue);

            if (in_array($optionValue, $valueArray)) {
                $optionAttributes['selected'] = 'selected';
            }
            
            $html .= '<option '
                . $this->_buildAttributeString($optionAttributes)
                . '>' 
                . $this->_view->escape($optionLabel) 
                . '</option>';
        }

        $html .= '</select>';

        return $html;
    }
}

// vim: sw=4:ts=4:sts=4:et
